<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>销售退货查询</title>
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/public.css" />
	</head>
	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">
				<div>
					<fieldset class="table-search-fieldset">
						<legend>搜索信息</legend>
						<form class="layui-form" action="" id="searchDataTimeAndCusName">
							<div class="layui-form-item">
								<div class="layui-inline" style="margin-left: -22px;">
									<label class="layui-form-label">往来时间：</label>
									<div class="layui-input-inline">
										<input type="text" class="layui-input" id="documentsCustomerTestOne" placeholder="yyyy-MM-dd" name="documentsCustomerTestOne">
									</div>
								</div>
								<div class="layui-inline" style="margin-left: -89px;">
									<label class="layui-form-label">至</label>
									<div class="layui-input-inline">
										<input type="text" class="layui-input" id="documentsCustomerTestTwo" placeholder="yyyy-MM-dd" name="documentsCustomerTestTwo">
									</div>
								</div>
								<div class="layui-inline developAndContract" style="margin-left: -20px;">
									<button class="layui-btn layui-btn-primary demo1">
										<i class="layui-icon layui-icon-down layui-font-12 develop"></i>
										<i class="layui-icon layui-icon-up layui-font-12 contract" style="display: none;"></i>
									</button>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label"  style="width: 130px;">按客户/单据号查询：</label>
									<div class="layui-input-inline">
										<input type="text" class="layui-input" id="selectTable" lay-filter="selectTable" />
									</div>
								</div>
								<div class="layui-inline">
									<button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="searchSaleRetrunInfo" id="searchSaleRetrunInfo">
										<i class="layui-icon"></i>
										搜 索
									</button>
								</div>
							</div>
						</form>
					</fieldset>
				</div>

				<div style="margin-top: 20px;">
					<div style="border: 1px solid #e6e6e6; width: 1274px;">
						<div id="btnList" style="display: none;">
							<button type="button" data-method="offset" data-type="auto" id="makeCollections" lay-event="makeCollections"
							 class="layui-btn layui-btn-normal layui-btn-sm">详细查找</button>

							<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="salWholeSingleReturn" id="salWholeSingleReturn">整单退货</button>
						</div>
						<div style="margin: 10px 10px 10px 0px;">
							<div style="position: relative;">
								<table class="layui-hide" id="commodity" lay-filter="commodity"></table>
							</div>
						</div>
					</div>
					<div style="border: 1px solid #e6e6e6; width: 1274px;">
						<div style="margin-left: 20px; padding-top: 10px;">单据的详细信息：<span style="color: red;" id="documentDetailsBillNo"></span>
								&nbsp;&nbsp;&nbsp;<span id="documentDetailsBillName"></span></div>
						<div style="margin: 10px 10px 10px 0px">
							<div>
								<table class="layui-hide" id="detailedInformationQuery"></table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<!-- 点击详细查找按钮 -->
		<div id="makeCollectionsInsertNewCommodityInfo" style="display: none; padding: 20px;">
			<form class="layui-form" id="detailSearch">
				<div class="layui-form-item">
					<label class="layui-form-label" style="margin-left: 40px;">客户名称:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<div class="layui-input-inline" style="width: 230px;">
							<select name="orcustName" id="orcustName" lay-verify="required">
								<option value="">所有客户</option>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 20px; margin-left: 40px;">
					<label class="layui-form-label">开单日期:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<input type="text" class="layui-input" id="currentTimeStart" name="currentTimeStart" placeholder="yyyy-MM-dd">
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 20px; margin-left: 40px;">
					<label class="layui-form-label">至:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<input type="text" class="layui-input" id="currentTimeEnd" name="currentTimeEnd" placeholder="yyyy-MM-dd">
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 40px; margin-left: 40px;">
					<label class="layui-form-label">仓库名称:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<div class="layui-input-inline" style="width: 230px;">
							<select name="ordepotName" id="ordepotName" lay-verify="required">
								<option value="">所有仓库</option>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 40px; margin-left: 40px;">
					<label class="layui-form-label">操&nbsp;&nbsp;作&nbsp;员:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<select name="orempName" id="orempName" lay-verify="required">
							<option value="">所有操作员</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 40px; margin-left: 40px;">
					<label class="layui-form-label">单据类型:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<select name="orsalOrdId" id="orsalOrdId" lay-verify="required">
							<option value="">所有单据</option>
							<option value="XS">销售单</option>
							<option value="XT">退货单</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 50px; margin-bottom: -10px; text-align: center;">
					<button type="button" class="layui-btn layui-btn-normal" id="findAndDetermineInDetail">确 定</button>
				</div>
			</form>
		</div>

		<script src="../../layui/layui.js"></script>
		<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
		<script>
			layui.use(['laydate', 'dropdown', 'table', 'jquery', 'form', 'tableSelect', 'layer'], function() {
				var laydate = layui.laydate;
				var dropdown = layui.dropdown;
				var table = layui.table;
				var $ = layui.jquery;
				var form = layui.form;
				var tableSelect = layui.tableSelect;
				var layer = layui.layer;

				//客户所有单据执行一个laydate实例 选择时间
				laydate.render({
					elem: '#documentsCustomerTestOne', //指定元素
					value: new Date()
				});
				laydate.render({
					elem: '#documentsCustomerTestTwo', //指定元素
					value: new Date()
				});
				
				//获取客户所有单据里的往来时间的前部分input框
				var documentsCustomerTestOne = $('#documentsCustomerTestOne');
				//获取客户所有单据里的往来时间的后部分input框
				var documentsCustomerTestTwo = $('#documentsCustomerTestTwo');
				
				//获取当前日期
				var time = new Date();
				var year = time.getFullYear();
				var moneth = (time.getMonth() + 1);
				var day = time.getDate();
				
				//今天
				if (moneth < 10) {
					if (day < 10) {
						var nowDate = year + '-0' + moneth + '-0' + day;
					} else {
						var nowDate = year + '-0' + moneth + '-' + day;
					}
				} else {
					if (day < 10) {
						var nowDate = year + '-' + moneth + '-0' + day;
					} else {
						var nowDate = year + '-' + moneth + '-' + day;
					}
				}
				//今天开始时间
				var nowStartDate = nowDate;
				
				if (moneth == 0) {
					moneth = 12;
					year = year - 1;
				}
				
				//昨天
				var lastOneDay = new Date(year, (moneth - 1), 0).getDate() - (1 - day);
				if (moneth < 10) {
					if (day < 1) {
						var lastOneDayStart = year + '-0' + (moneth - 1) + '-' + lastOneDay;
					} else if (day - 1 < 10) {
						var lastOneDayStart = year + '-0' + moneth + '-0' + (day - 1);
					} else if (day - 1 >= 10) {
						var lastOneDayStart = year + '-0' + moneth + '-' + (day - 1);
					}
				} else {
					if (day < 1) {
						var lastOneDayStart = year + '-' + (moneth - 1) + '-' + lastOneDay;
					} else if (day - 1 < 10) {
						var lastOneDayStart = year + '-' + moneth + '-0' + (day - 1);
					} else if (day - 1 >= 10) {
						var lastOneDayStart = year + '-' + moneth + '-' + (day - 1);
					}
				}
				
				//前天
				var lastThreeDay = new Date(year, (moneth - 1), 0).getDate() - (2 - day);
				if (moneth < 10) {
					if (day < 2) {
						var lastTwoDayStart = year + '-0' + (moneth - 1) + '-' + lastThreeDay;
					} else if (day - 2 < 10) {
						var lastTwoDayStart = year + '-0' + moneth + '-0' + (day - 2);
					} else if (day - 2 >= 10) {
						var lastTwoDayStart = year + '-0' + moneth + '-' + (day - 2);
					}
				} else {
					if (day < 2) {
						var lastTwoDayStart = year + '-' + (moneth - 1) + '-' + lastThreeDay;
					} else if (day - 2 < 10) {
						var lastTwoDayStart = year + '-' + moneth + '-0' + (day - 2);
					} else if (day - 2 >= 10) {
						var lastTwoDayStart = year + '-' + moneth + '-' + (day - 2);
					}
				}
				
				//最近七天
				var lastServenDay = new Date(year, (moneth - 1), 0).getDate() - (7 - day);
				if (moneth < 10) {
					if (day < 7) {
						var lastServenDayStart = year + '-0' + (moneth - 1) + '-' + lastServenDay;
					} else if (day - 7 < 10) {
						var lastServenDayStart = year + '-0' + moneth + '-0' + (day - 7);
					} else if (day - 7 >= 10) {
						var lastServenDayStart = year + '-0' + moneth + '-' + (day - 7);
					}
					if (day < 10) {
						var lastServenDayEnd = year + '-0' + moneth + '-0' + day;
					} else {
						var lastServenDayEnd = year + '-0' + moneth + '-' + day;
					}
				} else {
					if (day < 7) {
						var lastServenDayStart = year + '-' + (moneth - 1) + '-' + lastServenDay;
					} else if (day - 7 < 10) {
						var lastServenDayStart = year + '-' + moneth + '-0' + (day - 7);
					} else if (day - 7 >= 10) {
						var lastServenDayStart = year + '-' + moneth + '-' + (day - 7);
					}
					if (day < 10) {
						var lastServenDayEnd = year + '-' + moneth + '-0' + day;
					} else {
						var lastServenDayEnd = year + '-' + moneth + '-' + day;
					}
				}


                //获取最近一月最开的时间，最近一月最后一天时间（今天）
                var lastMonthDateStartDay = new Date(year, (moneth - 1), 0).getDate() - (30 - day);
                if (moneth < 10) {
                    if (day < 10) {
                        var lastMonthDateStart = year + '-0' + (moneth-1) + '-0' + lastMonthDateStartDay;
                        var lastMonthDateEnd = year + '-0' + moneth + '-0' + day;
                    } else {
                        if (day < 30) {
                            if(lastMonthDateStartDay<10){
                                var lastMonthDateStart = year + '-0' + (moneth - 1) + '-0' + lastMonthDateStartDay;
                            }else{
                                var lastMonthDateStart = year + '-0' + (moneth - 1) + '-' + lastMonthDateStartDay;
                            }
                        } else {
                            if(lastMonthDateStartDay<10){
                                var lastMonthDateStart = year + '-0' + moneth + '-0' + lastMonthDateStartDay;
                            }else{
                                var lastMonthDateStart = year + '-0' + moneth + '-' + lastMonthDateStartDay;
                            }
                        }
                        var lastMonthDateEnd = year + '-0' + moneth + '-' + day;
                    }
                } else {
                    if (day < 10) {
                        var lastMonthDateStart = year + '-' + (moneth-1) + '-0' + lastMonthDateStartDay;
                        var lastMonthDateEnd = year + '-' + moneth + '-0' + day;
                    } else {
                        if (day < 30) {
                            if(lastMonthDateStartDay<10){
                                var lastMonthDateStart = year + '-' + (moneth - 1) + '-0' + lastMonthDateStartDay;
                            }else{
                                var lastMonthDateStart = year + '-' + (moneth - 1) + '-' + lastMonthDateStartDay;
                            }
                        } else {
                            if(lastMonthDateStartDay<10){
                                var lastMonthDateStart = year + '-' + moneth + '-0' + lastMonthDateStartDay;
                            }else{
                                var lastMonthDateStart = year + '-' + moneth + '-' + lastMonthDateStartDay;
                            }
                        }
                        var lastMonthDateEnd = year + '-' + moneth + '-' + day;
                    }
                }
				
				//本月最开始的一天，本月现在这一天
				if (moneth < 10) {
					if (day < 10) {
						var thisMonthDateStart = year + '-0' + moneth + '-01';
						var thisMonthDateEnd = year + '-0' + moneth + '-0' + day;
					} else {
						var thisMonthDateStart = year + '-0' + moneth + '-01';
						var thisMonthDateEnd = year + '-0' + moneth + '-' + day;
					}
				} else {
					if (day < 10) {
						var thisMonthDateStart = year + '-' + moneth + '-01';
						var thisMonthDateEnd = year + '-' + moneth + '-0' + day;
					} else {
						var thisMonthDateStart = year + '-' + moneth + '-01';
						var thisMonthDateEnd = year + '-' + moneth + '-' + day;
					}
				}
				
				//上月最开始的时间,上月最后一天
				var myDate = new Date(year, (moneth - 1), 0);
				if (moneth < 10) {
					var precedingMonthStart = year + '-0' + (moneth - 1) + '-01';
					var precedingMonthEnd = year + '-0' + (moneth - 1) + '-' + myDate.getDate();
				} else {
					var precedingMonthStart = year + '-' + (moneth - 1) + '-01';
					var precedingMonthEnd = year + '-' + (moneth - 1) + '-' + myDate.getDate();
				}
				
				//所有时间最开始的那一天,所有时间最后一天
				var allTheTimeStart = "2000-01-01";
				var allTheTimeEnd = year + '-' + moneth + '-' + day;
				if (moneth < 10) {
					if (day < 10) {
						var allTheTimeEnd = year + '-0' + moneth + '-0' + day;
					} else {
						var allTheTimeEnd = year + '-0' + moneth + '-' + day;
					}
				} else {
					if (day < 10) {
						var allTheTimeEnd = year + '-' + moneth + '-0' + day;
					} else {
						var allTheTimeEnd = year + '-' + moneth + '-' + day;
					}
				}
				
				
				
				//做时间下拉选择 查询日期部分
				var developAndContract1 = $('.developAndContract1');
				var develop1 = $('.develop1');
				var contract1 = $('.contract1');
				developAndContract1.click(function() {
					develop1.css('display', 'none');
					contract1.css('display', 'block');
				});
				dropdown.render({
					elem: '.demo1',
					data: [{
						title: '今天',
						id: 1
					}, {
						title: '昨天',
						id: 2
					}, {
						title: '前天',
						id: 3
					}, {
						type: '-',
					}, {
						title: '最近七天',
						id: 4
					}, {
						title: '最近一月',
						id: 5
					}, {
						type: '-',
					}, {
						title: '本月',
						id: 6
					}, {
						title: '上月',
						id: 7
					}, {
						title: '所有时间',
						id: 8
					}],
					click: function(obj) {
						develop1.css('display', 'block');
						contract1.css('display', 'none');
						switch (obj.title) {
							case "今天":
								documentsCustomerTestOne.val(nowStartDate);
								documentsCustomerTestTwo.val(nowStartDate);
								break;
							case "昨天":
								documentsCustomerTestOne.val(lastOneDayStart);
								documentsCustomerTestTwo.val(lastOneDayStart);
								break;
							case "前天":
								documentsCustomerTestOne.val(lastTwoDayStart);
								documentsCustomerTestTwo.val(lastTwoDayStart);
								break;
							case "最近七天":
								documentsCustomerTestOne.val(lastServenDayStart);
								documentsCustomerTestTwo.val(lastServenDayEnd);
								break;
							case "最近一月":
								documentsCustomerTestOne.val(lastMonthDateStart);
								documentsCustomerTestTwo.val(lastMonthDateEnd);
								break;
							case "本月":
								documentsCustomerTestOne.val(thisMonthDateStart);
								documentsCustomerTestTwo.val(thisMonthDateEnd);
								break;
							case "上月":
								documentsCustomerTestOne.val(precedingMonthStart);
								documentsCustomerTestTwo.val(precedingMonthEnd);
								break;
							case "所有时间":
								documentsCustomerTestOne.val(allTheTimeStart);
								documentsCustomerTestTwo.val(allTheTimeEnd);
								break;
						}
					}
				});

                //搜索框内的弹出时间下拉列表内的最早时间
                /*$.post("/searchMortgageData", function(data){
                    allTheTimeStart=getDate(data);
                });*/

                function getDate(data) {
                    var date = new Date(data);
                    var m = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
                    var d = date.getDate() > 9 ? date.getDate() : '0' + date.getDate();
                    return date.getFullYear() + '-' + m + '-' + d;
                }


                // 监听商品销售，退货查询搜索操作
                $('#searchSaleRetrunInfo').on('click', function () {
                    var currentTimeStart=$('#documentsCustomerTestOne').val();
                    var currentTimeEnd=$('#documentsCustomerTestTwo').val();
                    var custNameAndId=$('#selectTable').val();
                    //执行搜索重载
                    table.reload('commodity', {
                        where:{
                            currentTimeStart:currentTimeStart,
                            currentTimeEnd:currentTimeEnd,
                            orcustNameAndId:custNameAndId
                        },
                        page: {
                            curr: 1
                        }
                    });
                    //重新渲染所有单据下表数据
                    table.reload('detailedInformationQuery',{
                        url:'/showSalesDescDataDatas',
                        where: {
                            orsalOrdId:''
                        }

                    });

                    //表单重置
                    $('#searchDataTimeAndCusName')[0].reset();

                    //重新为搜索框内的时间input框赋值
                    laydate.render({
                        elem: '#documentsCustomerTestOne', //指定元素
                        value: new Date()
                    });
                    laydate.render({
                        elem: '#documentsCustomerTestTwo', //指定元素
                        value: new Date()
                    });


                    //为单据的详细信息表格顶部的单号和客户名称重新赋值
                    $('#documentDetailsBillNo').html('');
                    $('#documentDetailsBillName').html('');

                });



                    //查询详细查找内的客户名称
                $.get(
                    "/selectCustName",function (obj) {
                        var cusJsonList = JSON.parse(JSON.stringify(obj));
                        for ( var i in cusJsonList ) {
                            $('select[name=orcustName]').append(new Option(cusJsonList[i].custName , cusJsonList[i].custName));
                        }
                        form.render('select');
                    }
                );
				//查询详细查找内的操作员
                $.get(
                    "/selectEmpName",function (obj) {
                        var empJsonList = JSON.parse(JSON.stringify(obj));
                        for ( var i in empJsonList ) {
                            $('select[name=orempName]').append(new Option(empJsonList[i].empName , empJsonList[i].empName));
                        }
                        form.render('select');
                    }
                );
				//查询详细查找内的仓库名称
                $.get(
                    "/selectDepName",function (obj) {
                        var depJsonList = JSON.parse(JSON.stringify(obj));
                        for ( var i in depJsonList ) {
                            $('select[name=ordepotName]').append(new Option(depJsonList[i].depotName , depJsonList[i].depotName));
                        }
                        form.render('select');
                    }
                );


                // 监听详细查找弹窗内的数据
                $('#findAndDetermineInDetail').on('click', function () {
                    var orcustNamesss=$('#orcustName').val();
                    var currentTimeStartsss=$('#currentTimeStart').val();
                    var currentTimeEndsss=$('#currentTimeEnd').val();
                    var ordepotNamesss=$('#ordepotName').val();
                    var orempNamesss=$('#orempName').val();
                    var orsalOrdIdsss=$('#orsalOrdId').val();

                    //执行搜索重载
                    table.reload('commodity', {
                        where:{
                            orcustName:orcustNamesss,
                            currentTimeStart:currentTimeStartsss,
                            currentTimeEnd:currentTimeEndsss,
                            ordepotName:ordepotNamesss,
                            orempName:orempNamesss,
                            orsalOrdId:orsalOrdIdsss
                        },
                        page: {
                            curr: 1
                        }
                    });
                    //重新渲染所有单据下表数据
                    table.reload('detailedInformationQuery',{
                        url:'/showSalesDescDataDatas',
                        where: {
                            orsalOrdId:''
                        }

                    });

                    //为单据的详细信息表格顶部的单号和客户名称重新赋值
                    $('#documentDetailsBillNo').html('');
                    $('#documentDetailsBillName').html('');

                    //表单重置
                    $('#detailSearch')[0].reset();

                    //重新为表单内的日期赋值
                    //详细查找内的开单日期前部分
                    laydate.render({
                        elem: '#currentTimeStart', //指定元素
                        value: new Date()
                    });

                    //详细查找内的开单日期后部分
                    laydate.render({
                        elem: '#currentTimeEnd', //指定元素
                        value: new Date()
                    });

                    //关闭弹窗
                    layer.closeAll();


                });


				
				//商品销售，退货查询上部分表格
                //定义变量保存应收金额，实收金额的值
                var orsalOrdReceivableMoney=0;
                var orsalOrdPaidInMoney=0;
				table.render({
					elem: '#commodity'
						// ,url: '../../demo/table/user/-page=1&limit=20.js'
						,
					/* data: [], */
					url: '/showSalesReturnQueryOrderDatas',
					totalRow: true,
					width: 1275,
					toolbar: '#btnList',
					cols: [
						[{
							type: 'radio',
							fixed: 'left',
						}, {
							field: 'orsalOrdId',
							width: 111,
							title: '单号',
							unresize: true,
							align: 'center',
                            totalRowText: '单据合计：<span id="countDataLength"></span>',
						}, {
							field: 'orsalOrdDate',
							width: 111,
							title: '开单日期',
							align: 'center',
							templet:function (obj) {
								return getDate(obj.orsalOrdDate);
                            }
						}, {
							field: 'orcustName',
							width: 111,
							title: '客户名称',
							align: 'center'
						}, {
							field: 'ordepotName',
							width: 110,
							title: '仓库名称',
							align: 'center'
						}, {
							field: 'orsalOrdReceivable',
							width: 110,
							title: '应收金额',
                            totalRowText: '<span id="orsalOrdReceivable"></span>',
							sort: true,
							align: 'center',
                            templet:function (obj) {
                                if('XT'==obj.orsalOrdId.substring(0,2)){
                                    orsalOrdReceivableMoney-=obj.orsalOrdReceivable;
                                    return -obj.orsalOrdReceivable;
                                }else if('XS'==obj.orsalOrdId.substring(0,2)){
                                    orsalOrdReceivableMoney+=obj.orsalOrdReceivable;
                                    return obj.orsalOrdReceivable;
                                }

                            }
						}, {
							field: 'orsalOrdPaidIn ',
							width: 110,
							title: '实收金额',
                            totalRowText: '<span id="orsalOrdPaidIn"></span>',
							sort: true,
							align: 'center',
                            templet:function (obj) {
                                if('XT'==obj.orsalOrdId.substring(0,2)){
                                    orsalOrdPaidInMoney-=obj.orsalOrdPaidIn;
                                    return -obj.orsalOrdPaidIn;
                                }else if('XS'==obj.orsalOrdId.substring(0,2)){
                                    orsalOrdPaidInMoney+=obj.orsalOrdPaidIn;
                                    return obj.orsalOrdPaidIn;
                                }

                            }
						}, {
							field: 'coupon',
							width: 110,
							title: '优惠金额',
                            totalRowText: '<span id="coupon"></span>',
							sort: true,
							align: 'center',
                            templet:function (obj) {
                                return 0;
                            }
						}, {
							field: 'operator',
							width: 110,
							title: '单据类型',
							align: 'center',
                            templet:function (obj) {
                                var operator;
                                if('XT'==obj.orsalOrdId.substring(0,2)){
                                    operator='销售退货支出'
                                }else if('XS'==obj.orsalOrdId.substring(0,2)){
                                    operator='商品销售付款'
                                }
                                return operator;
                            }
						}, {
							field: 'orempName',
							width: 110,
							title: '经办人',
							align: 'center'
						}, {
							field: 'orempName ',
							width: 110,
							title: '操作员',
							align: 'center',
                            templet:function (obj) {
                                return obj.orempName;
                            }
						}, {
							field: 'orsalOrdComment',
							width: 110,
							title: '备注',
							align: 'center'
						}]
					],
					page: true,
					limits: [10, 15, 20, 25, 50, 100],
					limit: 15,
					done: function(obj) {
                        //为应收金额，实收金额，优惠金额以及单据合计赋值
						$('#countDataLength').html(obj.data.length);
						$('#orsalOrdReceivable').html(orsalOrdReceivableMoney);
						$('#orsalOrdPaidIn').html(orsalOrdPaidInMoney);
						$('#coupon').html(0);
                        orsalOrdReceivableMoney=0;
                        orsalOrdPaidInMoney=0;

                        //默认选中第一条
                        $('.layui-table-view[lay-id=commodity] .layui-table-body tr[data-index=0] .layui-form-radio').click();
					}
				});

				var tanchuchengIndex = -1;
				
				//详细查找按钮与整单退货按钮
				table.on('toolbar(commodity)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
					switch (obj.event) {
						case "makeCollections":
							layer.open({
								type: 1,
								title: '<h3>查找</h3>',
								scrollbar: false, //屏蔽浏览器滚动条
								area: ['40%', '92%'],
								content: $('#makeCollectionsInsertNewCommodityInfo')
							});
							break;
                        case "salWholeSingleReturn":
                            //console.log(checkStatus.data[0].csalOrdId.substring(0,2));
                            if("XT"==checkStatus.data[0].orsalOrdId.substring(0,2)){
                                layer.msg("请选择单号以XS开头的数据！");
                            }else if("XS"==checkStatus.data[0].orsalOrdId.substring(0,2)){
                                $.post("/showSalesDescDataDatas?orsalOrdId="+checkStatus.data[0].orsalOrdId,function (data) {
                                    //alert(data);
                                    //window.billList = JSON.stringify(JSON.parse(data).data);
                                    var billList = JSON.parse(data).data;

                                    var j = 0;

                                    var len = billList.length;

                                    for ( var i = 0 ; i < len; i++ ) {
                                        if ( billList[j].orsalRetDescProNum == 0 ) {
                                            billList.splice(j , 1);
                                        } else {
                                            j++;
                                        }
                                    }


                                    if (billList.length == 0){
                                        layer.alert("当前选择的单，没有可退货的商品！");
                                        return;
                                    }

                                    window.billList = JSON.stringify(billList);

                                    tanchuchengIndex = layer.open({
                                        type:2,
                                        title: '',
                                        content:"sell_customerReturn.html",
                                        area:['98%','98%'],
                                        success:function (obj) {
                                            window.tanchuchengIndex = tanchuchengIndex;
                                        }
                                    });
                                });
                            }
                            break;
					}
				})
				
				//详细查找内的开单日期前部分
				laydate.render({
					elem: '#currentTimeStart', //指定元素
					value: new Date()
				});
				
				//详细查找内的开单日期后部分
				laydate.render({
					elem: '#currentTimeEnd', //指定元素
					value: new Date()
				});

				
				
				//商品销售，退货查询下部分详细单据信息表格
                //声明变量计算保存总金额，数量
                var countSaleOrderDescAllMoney=0;
                var countSaleOrderDescProductNumber=0;
				table.render({
					elem: '#detailedInformationQuery',
					data: [],
					totalRow: true,
					width: 1275,
					cols: [
						[{
							type: 'radio',
							fixed: 'left',
						}, {
							field: 'orproId ',
							width: 135,
							title: '商品编号',
							align: 'center',
							templet:function (obj) {
								return obj.orproId;
                            }
						}, {
							field: 'orproName',
							width: 135,
							title: '商品名称',
							unresize: true,
							totalRowText: '品种合计：<span id="countProductLength"></span>',
							align: 'center'
						}, {
							field: 'orsalOrdDescUnit',
							width: 135,
							title: '单位',
							align: 'center'
						}, {
							field: 'orsalOrdDescProPrice',
							width: 135,
							title: '单价',
							sort: true,
							align: 'center'
						}, {
							field: 'orsalOrdDescProNum',
							width: 135,
							title: '数量',
                            totalRowText: '<span id="countSalDescNumber"></span>',
							sort: true,
							align: 'center',
							templet:function (obj) {
                                countSaleOrderDescProductNumber+=obj.orsalOrdDescProNum;
								return obj.orsalOrdDescProNum;
                            }
						}, {
							field: 'aggregateAmount ',
							width: 135,
							title: '总金额',
                            totalRowText: '<span id="countSalDescAllManey"></span>',
							sort: true,
							align: 'center',
							templet:function (obj) {
                                countSaleOrderDescAllMoney+=obj.orsalOrdDescProNum*obj.orsalOrdDescProPrice;
								return obj.orsalOrdDescProNum*obj.orsalOrdDescProPrice;
                            }
						}, {
							field: 'orproSize',
							width: 135,
							title: '产品规格',
							align: 'center'
						}, {
							field: 'orsalOrdDescProBatchNum',
							width: 135,
							title: '产品批号',
							align: 'center'
						}, {
							field: 'orsalOrdDescProValidityDate',
							width: 135,
							title: '有效期至',
							align: 'center',
							templet:function (obj) {
								return getDate(obj.orsalOrdDescProValidityDate);
                            }
						}]
					],
					page: true,
					limits: [10, 15, 20, 25, 50, 100],
					limit: 15,
                    done:function (obj) {
					    console.log("countSaleOrderDescProductNumber");
                        //为表下面的总金额以及数量赋值
                        $('#countSalDescNumber').html(countSaleOrderDescProductNumber);
                        $('#countSalDescAllManey').html(countSaleOrderDescAllMoney);
                        countSaleOrderDescProductNumber = 0;
                        countSaleOrderDescAllMoney = 0;
                        //商品明细表所有商品类型数量
                        $('#countProductLength').html(obj.data.length);
                        //默认选中第一条
                        $('.layui-table-view[lay-id=detailedInformationQuery] .layui-table-body tr[data-index=0] .layui-form-radio').click();

                    }
				});

                //获商品销售，退货查询下部分详细单据信息表格单选选中数据
                table.on('radio(commodity)' , function (obj) {
                    //信息表格顶部的单号和客户名称赋值
                    $('#documentDetailsBillNo').html(obj.data.orsalOrdId);
                    $('#documentDetailsBillName').html(obj.data.orcustName);
                    table.reload('detailedInformationQuery',{
                        url:'/showSalesDescDataDatas',
                        where: {
                            orsalOrdId:obj.data.orsalOrdId
                        }
                    });
                });
				
				/* tableSelect.render({
					elem: '#selectTable',
					checkedKey: 'id',
					id: "custom1",
					table: {
						url: '../../api/table.json',
						toolbar: '#allDocumentsCustomerNameList',
						cols: [
							[{
									field: 'id',
									title: '编号'
								},
								{
									field: 'customName',
									title: '客户名称'
								},
								{
									field: 'contacts',
									title: '联系人'
								},
								{
									field: 'contactNumber',
									title: '联系电话'
								},
								{
									field: 'contactAddress',
									title: '联系地址'
								}
							]
						]
					},
					done: function(elem, data) {
						var NEWJSON = []
						layui.each(data.data, function(index, item) {
							NEWJSON.push(item.username)
						})
						elem.val(NEWJSON.join(","))
					}
				}); */
				
				//客户下拉表格内的修改按钮
				/* table.on('toolbar(custom1)', function(obj) {
				
					switch (obj.event) {
						case "amendCustomerName":
							layer.open({
								type: 1,
								title: '<h3 style="text-align: left;">修改客户商<h3>',
								scrollbar: false, //屏蔽浏览器滚动条
								area: ['58%', '75%'],
								content: $('#customerNameAlterInfo')
							});
							break;
					}
				}); */
				
				//客户下拉列表内的修改弹窗内的出生日期
				/* laydate.render({
					elem: '#dateOfBirth', //指定元素
					value: new Date()
				}); */
				

			});
		</script>
	</body>
</html>
